package cn.spiral.complain.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import cn.spiral.complain.dao.ComplainDao;
import cn.spiral.complain.entity.Complain;
import cn.spiral.core.dao.impl.BaseDaoImpl;

@Repository("complainDao")
public class ComplainDaoImpl extends BaseDaoImpl<Complain> implements ComplainDao {

	@Override
	public List<Object[]> getStatisDataByYear(int year) {
		
		//month(),year()是数据库从时间获得对应月，年的函数
		String sql="SELECT MONTH(comp_time),COUNT(comp_id) FROM Complain WHERE YEAR(comp_time) = ? GROUP BY MONTH(comp_time) ";
		SQLQuery sqlQuery=this.getSession().createSQLQuery(sql);
		sqlQuery.setParameter(0, year);
		return sqlQuery.list();
	}

}